package com.twu.biblioteca.Actions;

import com.twu.biblioteca.Interfaces.MenuItems;
import com.twu.biblioteca.Models.Book;
import com.twu.biblioteca.Models.BookCollection;

import java.util.ArrayList;
import java.util.List;

public class BookLister implements MenuItems
{
    private BookCollection bookCollection;
    private boolean displayAll;

    public BookLister(BookCollection bookCollection, boolean displayAll)
    {
        this.bookCollection = bookCollection;
        this.displayAll = displayAll;
    }

    public void takeAction()
    {
        System.out.println("Listing books:");

        List<Book> books = new ArrayList<Book>();
        if(displayAll)
        {
            displayBookTitles(bookCollection.returnBookList());
        }
        else
        {
            displayBookTitles(bookCollection.returnAvailableBookList());
        }
    }

    public void displayBookTitles(List<Book> books)
    {
        if(books != null)
        {
            for (Book book : books)
            {
                String bookTitle = book.getTitle();
                System.out.println(bookTitle);
            }
        }
    }
}
